import { useTable, LIST_TYPE } from '@crud/index';
import { getInvoiceList } from '@/api/crm-agency/dyj/invoice';

// 查询
export const tabsOptions = [
  { label: '未开票', value: 0 },
  { label: '已开票', value: 1 }
];

export const invoiceTypeMap: Record<number, any> = {
  0: '增值税普通发票',
  1: '增值税专用发票'
};
export const headTypeMap:Record<number, any> = {
  0: '个人',
  1: '企业'
};

// 表格
export const useTableList = (options: any = {}) => {
  const columns: any = [
    { label: '申请时间', prop: 'add_time', minWidth: 160, type: 'date', fixed: 'left' },
    { label: '代理名称', prop: 'colonel_name', minWidth: 160 },
    { label: '代理账号', prop: 'mobile', minWidth: 160 },
    { label: '发票类型', prop: 'invoice_type', minWidth: 120, render: (s:any) => invoiceTypeMap[s.row.invoice_type] },
    { label: '开票金额', prop: 'total_fee', minWidth: 120 },
    { label: '开票订单数', prop: 'order_count', minWidth: 120 },
    { label: '备注', prop: 'remark', minWidth: 120, render: 'remark', align: 'center' },
    { label: '操作', align: 'center', width: 120, render: 'actions', fixed: 'right' }
  ];

  return useTable({
    ...options,
    type: LIST_TYPE.AGENCY,
    params: {
      invoice_status: 0,
      key_word: '',
      from_dt: undefined,
      to_dt: undefined
    },
    columns: columns,
    getParams: ({ _timeArr = [], ...params }) => {
      // 处理时间参数
      if (_timeArr?.length) {
        const [begin, end] = _timeArr;
        params.from_dt = begin;
        params.to_dt = end;
      }
      return params;
    },
    getList: getInvoiceList
  });
};
